x86/mm: clean up pfec handling in gva_to_gfn
authorGeorge Dunlap <george.dunlap@citrix.com>
Thu, 4 Feb 2016 10:41:07 +0000 (11:41 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 4 Feb 2016 10:41:07 +0000 (11:41 +0100)
commite3e4ae8bb8314462496c2b065cfe4e8bc5205d5a
tree3fc36d1b1754f7eda5895500a31377001c10a88c
parentc41e0266dd59ab50b7a153157e9bd2a3ad114b53
x86/mm: clean up pfec handling in gva_to_gfn

At the moment, the pfec argument to gva_to_gfn has two functions:

* To inform guest_walk what kind of access is happenind

* As a value to pass back into the guest in the event of a fault.

Unfortunately this is not quite treated consistently: the hvm_fetch_*
function will "pre-clear" the PFEC_insn_fetch flag before calling
gva_to_gfn; meaning guest_walk doesn't actually know whether a given
access is an instruction fetch or not.  This works now, but will cause
issues when pkeys are introduced, since guest_walk will need to know
whether an access is an instruction fetch even if it doesn't return
PFEC_insn_fetch.

Fix this by making a clean separation for in and out functionalities
of the pfec argument:

1. Always pass in the access type to gva_to_gfn

2. Filter out inappropriate access flags before returning from gva_to_gfn.

(The PFEC_insn_fetch flag should only be passed to the guest if either NX or
SMEP is enabled.  See Intel 64 Developer's Manual, Volume 3, Chapter Paging,
PAGE-FAULT EXCEPTIONS)

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Signed-off-by: Huaitong Han <huaitong.han@intel.com>
Acked-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Tim Deegan <tim@xen.org>
xen/arch/x86/hvm/hvm.c
xen/arch/x86/mm/hap/guest_walk.c
xen/arch/x86/mm/shadow/multi.c
xen/include/asm-x86/paging.h